package com.maizhe.service.impl;

import com.maizhe.dao.OrganizationMapper;
import com.maizhe.dao.UserMapper;
import com.maizhe.entity.Organization;
import com.maizhe.entity.User;
import com.maizhe.entity.vo.OrganizationVo;
import com.maizhe.service.OrganizationService;
import com.maizhe.service.UserService;
import com.maizhe.util.DateUtil;
import com.maizhe.util.JsonResult;
import com.maizhe.util.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class OrganizationServiceImpl implements OrganizationService {
	
	@Autowired
	private OrganizationMapper organizationMapper;


	public List<OrganizationVo> findAll() {
		List<OrganizationVo> vos=new ArrayList<OrganizationVo>();
		List<Organization> list=organizationMapper.findAll();
		for(Organization org:list){
			vos.add(new OrganizationVo(org));
		}
		return vos;
	}

	public int saveOrganization(Organization organization) {
		int n=0;
		if(organization.getId()==null || "".equalsIgnoreCase(organization.getId())) {
			String id = UUIDGenerator.getUUID();
			organization.setId(id);
			organization.setCreateTime(new Date());
			n = organizationMapper.save(organization);

		}else{
			n = organizationMapper.update(organization);
		}
		return n;
	}

	public Organization findById(String id) {
		return organizationMapper.findById(id);
	}

	public int delete(String id) {
		return organizationMapper.delete(id);
	}
}
